//
//  GoOutRecordViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/12/15.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "GoOutRecordViewController.h"
#import "ImageDetailViewController.h"
#import<BaiduMapAPI_Map/BMKMapView.h>
#import<BaiduMapAPI_Location/BMKLocationService.h>
#import<BaiduMapAPI_Search/BMKGeocodeSearch.h>
#import <BaiduMapAPI_Search/BMKSuggestionSearch.h>
#import<BaiduMapAPI_Search/BMKSuggestionSearchOption.h>
#import <BaiduMapAPI_Map/BMKPinAnnotationView.h>
#import <BaiduMapAPI_Map/BMKPointAnnotation.h>
#import "UserHeadImageModel.h"

#define uploadPicInfo @"uploadPicInfo"//上传图片
#define postBusinessRecordInfo @"postBusinessRecordInfo"//提交公出记录

@interface GoOutRecordViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>
{
    UILabel *_dateLabel;//时间label
    NSTimer *_timer;//定时器
    NSMutableArray *_photoArr;//所拍照片的arr
    NSMutableArray *_photoButtonArr;//签退照片Buton
    BMKMapView *_mapView;  //地图
    BMKLocationService *_locService;  //定位
    BMKGeoCodeSearch *_geocodesearch; //地理编码主类，用来查询、返回结果信息
    UserHeadImageModel *_imageModel;//照片model
    BMKPointAnnotation* nowAnnotation;
    BMKPointAnnotation* readyAnnotation;
}
@property (nonatomic,strong) NSString *placeX;//纬度
@property (nonatomic,strong) NSString *placeY;//经度
@property (nonatomic,strong) NSString *addressInfo;//当前地址
@property (nonatomic,strong) NSString *locationTime;//当前定位时间
@property (nonatomic,strong) NSString *altitude;//海拔
@end

@implementation GoOutRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLeftBackNavigation];
    [self setNavigationTitle:@"公出实时记录"];
    [self getDateStr];
    [self creatView];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    CLLocationCoordinate2D coordinate=CLLocationCoordinate2DMake([self.addressX doubleValue], [self.addressY doubleValue]);
    readyAnnotation= [[BMKPointAnnotation alloc]init];
    readyAnnotation.coordinate = coordinate;
    readyAnnotation.title = @"";
    [_mapView addAnnotation:readyAnnotation];

}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil

}

#pragma mark -停止计时器并返回上一页
- (void)backClick{
    
    //关掉计数器
    if ([_timer isValid]) {
        [_timer invalidate];
        _timer=nil;
    }
    [super backClick];
}

#pragma mark - creatView

- (void)creatView{

    UIView *dateView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 80)];
    dateView.backgroundColor=COLOR_MIDBLUE;
    [self.view addSubview:dateView];
    //时间的label
    _dateLabel=[MyControl creatLabelWithFrame:CGRectMake(10, 15, IPHONE_WIDTH-20, 50) text:@""];
    _dateLabel.textAlignment=NSTextAlignmentCenter;
    _dateLabel.font=FONT_17;
    _dateLabel.textColor=[UIColor whiteColor];
    [dateView addSubview:_dateLabel];
    
    //添加地图视图
    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, dateView.y+dateView.height, IPHONE_WIDTH, 250)];
    _mapView.showsUserLocation = YES; //是否显示定位图层（即我的位置的小圆点）
    _mapView.zoomLevel = 6;//地图显示比例
    _mapView.mapType = BMKMapTypeStandard;//设置地图为空白类型
    _mapView.showMapScaleBar = YES;
    //自定义比例尺的位置
    _mapView.mapScaleBarPosition = CGPointMake(_mapView.frame.size.width - 70, _mapView.frame.size.height - 68);
    [self.view addSubview:_mapView];
    
    BMKLocationViewDisplayParam *displayParam = [[BMKLocationViewDisplayParam alloc]init];
    displayParam.isRotateAngleValid = true;//跟随态旋转角度是否生效
    displayParam.isAccuracyCircleShow = false;//精度圈是否显示
    displayParam.locationViewImgName= @"icon_mark@2x";//定位图标名称
    displayParam.locationViewOffsetX = 0;//定位偏移量(经度)
    displayParam.locationViewOffsetY = 0;//定位偏移量（纬度）
    [_mapView updateLocationViewWithParam:displayParam];
    
    
    _geocodesearch = [[BMKGeoCodeSearch alloc] init];
    
    _geocodesearch.delegate = self;
    [self startLocation];//开始定位方法
    
    //创建照片要用的数组
    _photoArr=[NSMutableArray new];
    _photoButtonArr=[NSMutableArray new];


    
    //拍照提交按钮
    UIButton *subBtn=[MyControl creatButtonWithFrame:CGRectMake(15, IPHONE_HEIGHT-55-64, IPHONE_WIDTH-30, 40) target:self sel:@selector(submitClick:) tag:150 image:nil title:@"提交"];
    subBtn.backgroundColor=COLOR_MIDBLUE;
    subBtn.layer.cornerRadius=5;
    [subBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:subBtn];
    
    //添加图片
    CGFloat buttonWidth=(IPHONE_WIDTH-80*3)/4;//button间隔
    for (int i=0; i<4; i++) {
        //高度间隔为20
        UIButton *signButton=[MyControl creatButtonWithFrame:CGRectMake(buttonWidth*(i%3+1)+80*(i%3), subBtn.y-100*(i/3+1)-10, 80, 80) target:self sel:@selector(addPhoto:) tag:140+i image:@"AlbumAddBtn@2x" title:nil];
        if (i!=0) {
            signButton.hidden=YES;
        }
        [self.view addSubview:signButton];
        [_photoButtonArr addObject:signButton];
    }
    
    UILabel *signInLabel=[MyControl creatLabelWithFrame:CGRectMake(10, subBtn.y-100-20-30, IPHONE_WIDTH-20, 20) text:@"拍照:"];
    [self.view addSubview:signInLabel];
    
    _mapView.height=signInLabel.y-_mapView.y-10;
    
}



#pragma mark - 拍照按钮点击

- (void)addPhoto:(UIButton *)button{
    //最后一张图片为添加按钮对其进行特殊处理
    if (button.tag-140==_photoArr.count) {
        if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
            [LZXHelper postMessageWithText:@"您的手机还不支持照相功能！" View:self.view];
            return;
        }
        if (_photoArr.count>=3) {
            [LZXHelper postMessageWithText:@"最多只能提交3张照片！" View:self.view];
            return;
        }
        
        UIImagePickerController *imagePickerController=[[UIImagePickerController alloc]init];
        imagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
        imagePickerController.delegate=self;
        imagePickerController.allowsEditing=YES;
        [self presentViewController:imagePickerController animated:NO completion:nil];
    }else{
        ImageDetailViewController *imageViewController=[ImageDetailViewController new];
        imageViewController.image=_photoArr[button.tag-140];
        [self.navigationController pushViewController:imageViewController animated:YES];
    }
    
}

#pragma mark -提交按钮点击事件
- (void)submitClick:(UIButton *)button{
    NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
    NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);
    if (_photoArr.count==0) {
        [LZXHelper postMessageWithText:@"请先拍照！" View:self.view];
        return;
    }
    //        NSString *otherButtonTitle2 = NSLocalizedString(@"拍照", nil); 不支持拍照
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确认要提交吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
                                   {
                                       //cancel Button
                                   }];
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                                  {
                                      NSThread* myThread = [[NSThread alloc] initWithTarget:self
                                                                                   selector:@selector(uploadPhotoImage)
                                                                                     object:nil];
                                      [myThread start];
                                  }];
    
    
    // Add the actions.
    [alertController addAction:otherAction];
    
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];

}

#pragma mark -相册Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //编辑时调用
    if (!info[@"UIImagePickerControllerEditedImage"])
    {
        return;
    }
    UIImage *image=info[@"UIImagePickerControllerEditedImage"];
    [_photoArr insertObject:image atIndex:0];
    //将拍的图片显示出来
    for (int i=0;i<_photoButtonArr.count;i++) {
        UIButton *photo=_photoButtonArr[i];
        if (i<_photoArr.count) {
            UIImage *image=_photoArr[i];
            [photo setImage:image forState:UIControlStateNormal];
            photo.hidden=NO;
        }else{
            photo.hidden=YES;
        }
        if (i==_photoArr.count) {
            //[photo setImage:[UIImage imageNamed:@"AlbumAddBtn@2x"] forState:UIControlStateNormal];
            photo.hidden=NO;
        }

    }
    //如果照片达到三个 就隐藏增加按钮
    if (_photoArr.count==_photoButtonArr.count-1) {
        UIButton *photo=[_photoButtonArr lastObject];
        photo.hidden=YES;
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}



#pragma mark -获取当前时间
- (void)getDateStr{
    //    if (!_dateStr) {
    //        return ;
    //    }
    //    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    //    [formatter setDateFormat:@"yyyy-MM-dd \n HH:mm:ss"];
    //    NSDate *serverDate=[formatter dateFromString:_dateStr];
    //
    //    NSInteger time=[NSDate dateWithTimeIntervalSince1970:<#(NSTimeInterval)#>]
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
    
}
#pragma mark -定时器刷新函数
- (void)timerFunc

{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM-dd \n HH:mm:ss"];
    
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    
    _dateLabel.text=timestamp;//时间在变化的语句
    
    //NSLog(@"%@",timestamp);
    static unsigned int num;
    num++;
    //每隔60秒刷新一次页面数据
    if (num%60==0) {
        [self startLocation];
    }
    
}

//开始定位
-(void)startLocation
{
    //初始化BMKLocationService
    if (!_locService) {
        _locService = [[BMKLocationService alloc]init];
        _locService.delegate = self;
        _locService.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    }
    //启动LocationService
    [_locService startUserLocationService];
}


//实现相关delegate 处理位置信息更新
//处理方向变更信息
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
    NSLog(@"heading is %@",userLocation.heading);
}

//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    self.placeX=[NSString stringWithFormat:@"%f",userLocation.location.coordinate.latitude];
    self.placeY=[NSString stringWithFormat:@"%f",userLocation.location.coordinate.longitude];
    //普通态
    //以下_mapView为BMKMapView对象
    [_mapView updateLocationData:userLocation]; //更新地图上的位置
    _mapView.centerCoordinate = userLocation.location.coordinate; //更新当前位置到地图中间
    //地理反编码
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate;
    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
    
    if(flag){
        NSLog(@"反geo检索发送成功");
        //获取定位成功后的时间
        NSDateFormatter *formatter=[NSDateFormatter new];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        self.locationTime=[formatter stringFromDate:[NSDate date]];
        
        //计算最小经纬度和最大经纬度两点之间的距离
        int dictance = [self getDistance];
        //这个数组就是百度地图比例尺对应的物理距离，其中2000000对应的比例是3，5对应的是21；可能有出入可以根据情况累加
        NSArray *zoomLevelArr = [[NSArray alloc]initWithObjects:@"2000000", @"1000000", @"500000", @"200000", @"100000", @"50000", @"25000", @"20000", @"10000", @"5000", @"2000", @"1000", @"500", @"200", @"100", @"50", @"20", @"10", @"5", nil];
        for (int j=0; j<zoomLevelArr.count; j++) {
            if (j + 1 < zoomLevelArr.count) {
                if (dictance < [zoomLevelArr[j] intValue] && dictance > [zoomLevelArr[j+1] intValue] ) {
                    [_mapView setZoomLevel:j+5];
                    break;
                }
            }
        }
        [_locService stopUserLocationService];
    }else{
        NSLog(@"反geo检索发送失败");
    }
}

#pragma mark -地图区域改变完成后会调用此接口
//- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
//    
//    //CGPoint touchPoint = [gestureRecognizer locationInView:_mapView];//这里touchPoint是点击的某点在地图控件中的位置
//    //取地图的中心
//    CLLocationCoordinate2D touchMapCoordinate =
//    [_mapView convertPoint:self.view.center toCoordinateFromView:_mapView];//这里touchMapCoordinate就是该点的经纬度了
//    //地理反编码
//    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
//    reverseGeocodeSearchOption.reverseGeoPoint = touchMapCoordinate;
//    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
//    
//    if(flag){
//        NSLog(@"反geo检索发送成功");
//        [_locService stopUserLocationService];
//    }else{
//        NSLog(@"反geo检索发送失败");
//    }
//}

//根据anntation生成对应的View
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if (annotation==readyAnnotation) {
        NSString *AnnotationViewID = @"annotation";
        //根据指定标识查找一个可被复用的标注View，一般在delegate中使用，用此函数来代替新申请一个View
        BMKAnnotationView *annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
        if (annotationView == nil) {
            annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
            ((BMKPinAnnotationView*)annotationView).pinColor = BMKPinAnnotationColorRed;
            ((BMKPinAnnotationView*)annotationView).animatesDrop = NO;
            annotationView.image=[UIImage imageNamed:@"k_current@2x"];
        }
        
        annotationView.centerOffset = CGPointMake(0, -(annotationView.frame.size.height * 0.5));
        annotationView.annotation = annotation;
        annotationView.canShowCallout = YES;
        [self addTextInView:annotationView text:@"公出位置" backgroundColor:[UIColor blackColor] textColor:[UIColor blackColor]];
        return annotationView;
    }
    NSString *AnnotationViewID = @"annotationViewID";
    //根据指定标识查找一个可被复用的标注View，一般在delegate中使用，用此函数来代替新申请一个View
    BMKAnnotationView *annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
    if (annotationView == nil) {
        annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
        ((BMKPinAnnotationView*)annotationView).pinColor = BMKPinAnnotationColorRed;
        ((BMKPinAnnotationView*)annotationView).animatesDrop = NO;
        annotationView.image=[UIImage imageNamed:@"icon_mark@2x"];
    }
    
    annotationView.centerOffset = CGPointMake(0, -(annotationView.frame.size.height * 0.5));
    annotationView.annotation = annotation;
    annotationView.canShowCallout = YES;
    [self addTextInView:annotationView text:@"当前位置" backgroundColor:[UIColor blackColor] textColor:[UIColor blackColor]];
    return annotationView;
}

#pragma mark -气泡文字提示
- (void)addTextInView:(BMKAnnotationView *)annotationView text:(NSString *)text backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor{
    //添加文字说明
    UIView *backView=[[UIView alloc]initWithFrame:CGRectMake((60-annotationView.center.x)/2, annotationView.height, 60, 20)];
    backView.center=CGPointMake(annotationView.center.x+5, annotationView.height+10);
    backView.backgroundColor=[UIColor clearColor];
    [annotationView addSubview:backView];
    
    UIView *alphoView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, backView.width, backView.height)];
    alphoView.alpha=0.1;
    alphoView.backgroundColor=backgroundColor;
    [backView addSubview:alphoView];
    
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, backView.width, backView.height)];
    label.backgroundColor=[UIColor clearColor];
    label.font=FONT_13;
    label.textAlignment=NSTextAlignmentCenter;
    label.text=text;
    [backView addSubview:label];
}

#pragma mark -------------地理反编码的delegate---------------
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
    //NSLog(@"address:%@----%@",result.addressDetail,result.address);
    self.addressInfo=result.address;
    [_mapView removeAnnotation:nowAnnotation];
    //    //增加气泡
    nowAnnotation = [[BMKPointAnnotation alloc]init];
    nowAnnotation.coordinate = result.location;
    nowAnnotation.title = result.address;
    [_mapView addAnnotation:nowAnnotation];
//        _mapView.centerCoordinate = result.location;
    //addressDetail:     层次化地址信息
    //address:    地址名称
    //businessCircle:  商圈名称
    // location:  地址坐标
    //  poiList:   地址周边POI信息，成员类型为BMKPoiInfo
}

#pragma mark -计算最远的距离
- (double)getDistance{
    //第一个坐标
    
    CLLocation *current=[[CLLocation alloc] initWithLatitude:self.placeX.doubleValue longitude:self.placeY.doubleValue];
    
    //第二个坐标
    
    CLLocation *before=[[CLLocation alloc] initWithLatitude:self.addressX.doubleValue longitude:self.addressY.doubleValue];
    CLLocationDistance meters=[current distanceFromLocation:before];
    return meters;
}

#pragma mark -上传照片
- (void)uploadPhotoImage{
    
    NSMutableDictionary *picList=[NSMutableDictionary new];
    NSMutableArray *imageArr=[NSMutableArray new];
    
    for (int i=0; i<_photoArr.count; i++) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setDateFormat:@"yyyyMMddHHmmssSSS"];
        //以时间为照片命名
        NSString *timestamp = [[formatter stringFromDate:[NSDate date]] stringByAppendingString:@".jpg"];
        
        UIImage *image=_photoArr[i];
        NSData *date = UIImageJPEGRepresentation(image, 0.5);
        NSString * imageStr = [date base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
        NSDictionary *dict=@{
                             @"picName":timestamp,
                             @"picBase":imageStr,
                             @"picType":@"gongChu",
                             };
        
        [imageArr addObject:dict];
    }
    
    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:picList options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:uploadPicInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        _imageModel=[[UserHeadImageModel alloc]initWithResponse:responseObject];
        if ([_imageModel.code isEqualToString:@"200"]) {
            [self postBusinessRecordInfoRequest];
        }else if([_imageModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_imageModel.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
    
}


#pragma mark -提交公出记录
- (void)postBusinessRecordInfoRequest{
    
    //添加照片信息
    NSMutableArray *imageInfoArr=[NSMutableArray new];
    for (int i=0; i<_imageModel.dataArr.count; i++) {
        NSMutableDictionary *dict=[NSMutableDictionary new];
        UserHeadImageModel *model=_imageModel.dataArr[i];
        [dict setObject:model.picPath forKey:@"picPath"];
        [dict setObject:model.picName forKey:@"picName"];
        [imageInfoArr addObject:dict];
    }
    
    //参数
    NSDictionary *dict=@{
                         @"latitude":self.placeX?self.placeX:@"",
                         @"longitude":self.placeY?self.placeY:@"",
                         @"altitude":self.altitude?self.altitude:@"33",
                         @"address":self.addressInfo?self.addressInfo:@"0",
                         @"locationTime":self.locationTime?self.locationTime:@"",
                         };
    
    NSMutableArray *requestArr=[NSMutableArray arrayWithObject:dict];
    NSDictionary *newDict=@{
                            @"id":self.vacateBillId?self.vacateBillId:@"",
                            @"locationList":requestArr,
                            @"picList":imageInfoArr,
                            };
    
    //    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:newDict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postBusinessRecordInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
            [self backClick];
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
